package com.zhonghui.dolo.manager.dao.impl;

import com.zhonghui.dolo.manager.dao.AdminDao;
import com.zhonghui.dolo.manager.dao.mapper.AdminMapper;
import com.zhonghui.dolo.manager.model.Admin;
import com.zhonghui.dolo.manager.model.AdminExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class AdminDaoImpl implements AdminDao {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Admin findAdminByNameAndPwd(String uname, String upwd) {
        AdminExample example = new AdminExample();
        example.createCriteria().andAdminNameEqualTo(uname).andPasswordEqualTo(upwd);

        List<Admin> adminList = adminMapper.selectByExample(example);
        if (adminList != null && adminList.size() > 0) {
            return adminList.get(0);
        }
        return null;
    }

    @Override
    public Admin findAdminByName(String uname) {
        AdminExample example = new AdminExample();
        example.createCriteria().andAdminNameEqualTo(uname);

        List<Admin> adminList = adminMapper.selectByExample(example);
        if (adminList != null && adminList.size() > 0) {
            return adminList.get(0);
        }
        return null;
    }
}
